﻿using CommandProcessor.Command;
using Data.Infrastructure;
using Data.Repositories;
using Domain.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Domain.Handlers
{
    public class DeleteProductHandler : ICommandHandler<DeleteProductCommand>
    {
        private readonly IProductRepository ProductRepository;
        private readonly IUnitOfWork unitOfWork;
        public DeleteProductHandler(IProductRepository ProductRepository, IUnitOfWork unitOfWork)
        {
            this.ProductRepository = ProductRepository;
            this.unitOfWork = unitOfWork;
        }
        public ICommandResult Execute(DeleteProductCommand command)
        {
            var Product = ProductRepository.GetById(command.ID);
            ProductRepository.Delete(Product);
            unitOfWork.Commit();
            return new CommandResult(true);
        }


        public ICommandResult ExecuteRange(IEnumerable<DeleteProductCommand> commands)
        {
            var ids = commands.Select(y => y.ID);
            ProductRepository.Delete(x => ids.Contains(x.ID));
            unitOfWork.Commit();
            return new CommandResult(true);
        }
        public ICommandResult DeleteRange(IEnumerable<DeleteProductCommand> commands)
        {
            throw new NotImplementedException();
        }
    }
}
